#include "pch.h"

#include "memory/win32/win32heap.h"



namespace Win32
{

	///
	void Win32Heap::Setup()
	{

	}



	///
	Win32Heap::Win32Heap()
	{

	}

	///
	Win32Heap::Win32Heap(const char *name, size_t initSize, size_t maxSize)
	{
		this->m_name = name;

		this->m_heap = ::HeapCreate(0, initSize, maxSize);

		ULONG heapFragValue = 2;

		HeapSetInformation(this->m_heap, HeapCompatibilityInformation, &heapFragValue, sizeof(heapFragValue));
	}


	///
	Win32Heap::~Win32Heap()
	{
		::HeapDestroy(this->m_heap);

		this->m_heap = 0;
	}

	///
	const char * Win32Heap::GetName() const 
	{
		return this->m_name;
	}


	///
	void * Win32Heap::Alloc(size_t size)
	{
		return ::HeapAlloc(this->m_heap, HEAP_GENERATE_EXCEPTIONS, size);
	}


	///
	void * Win32Heap::Realloc(void *ptr, size_t size)
	{
		return ::HeapReAlloc(this->m_heap, HEAP_GENERATE_EXCEPTIONS, ptr, size);
	}


	///
	void Win32Heap::Free(void * ptr)
	{
		::HeapFree(this->m_heap, 0, ptr);
	}

}